package com.wljy.developtool.dto;

import java.util.HashMap;
import java.util.Map;

public class Result<T> {

    private int code;

    private String message;

    private T data;

    public static <T> Result<T> success(T data) {
        return success(200,data);
    }

    public static <T> Result<T> map(String key,T data) {
        Result result = new Result();
        Map<String,T> map1 = new HashMap<>(1);
        map1.put(key,data);
        result.setCode(200);
        result.setData(map1);
        return result;
    }

    public static <T> Result<T> success(int code,T data) {
        Result result = new Result();
        result.setCode(code);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(int code,String errMsg) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(errMsg);
        return result;
    }

    public static <T> Result<T> fail(String errMsg) {
        Result result = new Result();
        result.setCode(400);
        result.setMessage(errMsg);
        return result;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
